﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="detailandmed_v5_Vastus", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(DetailandmedV5Vastus))]
    public class DetailandmedV5VastusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IDetailandmedV5Vastus clazz;
        
        public DetailandmedV5VastusSerializer(IDetailandmedV5Vastus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Ettevotjad!=null) {
                Writer.WriteStartElement("ettevotjad");
                global::Xtee.Core.SerializationMetadata metaEttevotjad = this.GetMetaData(clazz.Ettevotjad);
                Writer.WriteTypeAttribute(metaEttevotjad.TypeQualifiedName.Namespace, metaEttevotjad.TypeQualifiedName.Name);
                metaEttevotjad.NewSerializer(clazz.Ettevotjad).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("leitud_ettevotjate_arv");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.LeitudEttevotjateArv))).ToString());
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ettevotjad") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaEttevotjad = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Ettevotjad>(Reader, "detailandmed_v5_ettevotjad", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                    clazz.Ettevotjad = metaEttevotjad.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Ettevotjad>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("ettevotjad");
                        metaEttevotjad.NewSerializer(clazz.Ettevotjad).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="leitud_ettevotjate_arv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_Vastus>leitud_ettevotjate_arv");
                }
                clazz.LeitudEttevotjateArv = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("leitud_ettevotjate_arv")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>detailandmed_v5_Vastus>leitud_ettevotjate_arv", Reader.LocalName);
            }
        }
    }
}
